package org.jiuling.request.http.handle;

import org.jiuling.basics.enums.HttpRequestMethodEnum;
import org.jiuling.basics.util.InputStreamUtil;
import org.jiuling.basics.validation.ObjectVerify;
import org.jiuling.request.http.HttpRequest;
import org.jiuling.request.http.core.HttpRequestCore;
import org.jiuling.request.http.model.HttpRequestParam;
import org.jiuling.request.http.model.HttpResponse;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;

/**
 * Http处理
 * @author 紫灵
 * @date 2024年08月28日 20时55分50秒
 */
public class HttpRequestHandle extends HttpRequestCore implements HttpRequest {

    public HttpRequestHandle(URI uri) {
        super(uri);
    }

    @Override
    public HttpResponse send() throws IOException {
        HttpURLConnection httpURLConnection = (HttpURLConnection) super.openConnection();
        httpURLConnection.setRequestMethod(super.httpRequestMethod.name());
        // 连接
        httpURLConnection.connect();
        // 封装相应
        HttpResponse httpResponse = super.packageHttpResponse(httpURLConnection);
        // 断开连接
        httpURLConnection.disconnect();
        ResponseHandle.errorHandle(httpResponse);
        return httpResponse;
    }
}
